﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WPFTrees.DataStructures;
using WPFTrees.Parser;

namespace WPFTrees
{
    /// <summary>
    /// Implementace IComparer radici uzly stromu podle poctu listu v podstromu.
    /// </summary>
    class LeafComparer:IComparer<NTreeNode<NewickNode>>
    {
        bool _bReverse;

        /// <summary>
        /// Vytvori novou instanci LeafComparer.
        /// </summary>
        /// <param name="reverse">true pokud se ma poradi porovnani otocit.</param>
        public LeafComparer(bool reverse)
        {
            _bReverse = reverse;
        }

        public int Compare(NTreeNode<NewickNode> x, NTreeNode<NewickNode> y)
        {
            int res = x.Leaves.CompareTo(y.Leaves);
            if (_bReverse)
                return -res;
            else return res;
        }
    }
}
